pipeline {
    agent any
    // 设置全局选项
    options {
        // 构建超时时间设置为 1 小时
        timeout(time: 1, unit: 'HOURS')
        // 保持最近 10 次构建记录
        buildDiscarder(logRotator(numToKeepStr: '10'))
        // 禁用并发构建
        disableConcurrentBuilds()
    }
    stages {
        stage('Init') {
            steps {
                script {
                    // 动态生成参数，每次构建前执行,和parameters.groovy效果一样
                    properties([
                        parameters([
                            string(name: 'PERSON', defaultValue: 'World', description: '输入你要打招呼的人'),
                            choice(name: 'ENVIRONMENT', choices: ['dev', 'test', 'prod'], description: '选择环境'),
                            string(name: 'dynamicParam', defaultValue: 'new', description: '动态参数')
                        ])
                    ])
                }
            }
        }
        stage('Echo'){
            steps {
                echo "Hello ${params.dynamicParam}!"
                echo "PERSON: ${params.PERSON}"
                echo "Environment: ${params.ENVIRONMENT}"
            }
        }
    }
}